package logic

import (
	"context"
	"order_srv/modile/mysql"

	"order_srv/internal/svc"
	"order_srv/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *order.OrderListRequest) (*order.OrderListResponse, error) {
	// todo: 订单列表

	o := mysql.OrderLx{}

	list, err := o.OrderList(in.Keyword, int(in.Page), int(in.PageSize))
	if err != nil {
		logx.Error("列表查询失败", err)
		return nil, err
	}

	var orderList []*order.Orders

	for _, v := range list {

		orderList = append(orderList, &order.Orders{
			UserId:  v.UserId,
			GoodsSn: v.GoodsSn,
			Amount:  v.Amount,
			Payment: int64(v.Payment),
			Status:  int64(v.Status),
			OrderId: int64(v.ID),
		})
	}

	return &order.OrderListResponse{OrderList: orderList}, nil
}
